﻿@model UserRegisterModel
@{
    Layout = "_LayoutLogin";
}

<!-- 注册表单 -->
<form method="post" asp-controller="account" asp-action="register" enctype="multipart/form-data">
    <h2 class="form-caption">创建新账号</h2>

    <div class="row mb-4">
        <label class="form-label" for="name">用户昵称</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-user"></i>
            <input type="text" class="form-control login-input-with-ico" id="name" name="name" placeholder="请输入用户昵称" maxlength="20" asp-for="Name">
        </div>
        <span asp-validation-for="Name" class="text-danger small"></span>
    </div>

    <div class="row mb-4">
        <label class="form-label" for="username">用户名</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-user"></i>
            <input type="text" class="form-control login-input-with-ico" id="username" name="username" placeholder="请输入用户名" maxlength="20" asp-for="UserName">
        </div>
        <span asp-validation-for="UserName" class="text-danger small"></span>
    </div>

    <div class="row mb-4">
        <label class="form-label" for="password">用户密码</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-password"></i>
            <input type="password" class="form-control login-input-with-ico" id="password" name="password" placeholder="请输入用户密码" maxlength="20" asp-for="Password">
        </div>
        <span asp-validation-for="Password" class="text-danger small"></span>
    </div>

    <div class="row mb-4">
        <label class="form-label" for="confirmpassword">确认密码</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-password"></i>
            <input type="password" class="form-control login-input-with-ico" id="confirmpassword" name="confirmpassword" placeholder="请再次输入用户密码" maxlength="20" asp-for="ConfirmPassword">
        </div>
        <span asp-validation-for="ConfirmPassword" class="text-danger small"></span>
    </div>

    <div class="row-cols-2 mb-4 text-center">
        <button type="submit" class="btn btn-primary form-button">注册账号</button><br />
        <input id="hidResult" type="hidden" value="@Model?.Result" />
        <input id="hidMsg" type="hidden" value="@Model?.ResultMessage" />
    </div>

    <div class="row-cols-2 mb-4 text-center">
        已有账号? <a asp-controller="account" asp-action="login">立即登录</a>
    </div>
</form>

@section Scripts {
    <script type="text/javascript">
        window.onload = function(){
            var result = document.querySelector("#hidResult").value;
            var msg = document.querySelector("#hidMsg").value;
            if(result && result == "1"){
                var showMsg = (msg && msg.length > 0) ? msg :"注册成功！";
                showMessage("用户注册", showMsg, function(){
                    window.location.href="/account/login";
                });
            }
            else if(msg && msg.length > 0){
                showMessage("用户注册", msg);
            }
        };
    </script>
}